﻿@using Kobets.Automation.Chimera.Orchestrator.Shared
@model IEnumerable<Kobets.Automation.Chimera.Orchestrator.Models.Profiles>

<script type="text/javascript">
    $(window).load(function () {
        $('#accordion').accordion("option", "active", @ViewBag.InitialSelectedGroup);
    });
</script>

<div class="sidebar" id="sidebar">
   @{
        Html.RenderPartial("_AgentsSidebar");
    }
</div>

<div class="mainbar">
    @{
        Html.BeginForm("Execute", "Execute", FormMethod.Post, new { name = "eFrm", id = "eFrm"});
    }
    <div id="executeForm">
        <table>
            <tr>
                <td>Test package:</td>
                <td>@Html.DropDownList("ExecutionPackage")</td>
            </tr>
            <tr>
                <td>Group:</td>
                <td>
                    <select id="Group" name="Group" onchange="javascript:$('#accordion').accordion('option', 'active', $('#Group').prop('selectedIndex'));UpdateTime();">
                        @foreach (var item in (List<EnchancedSelectListItem>)ViewBag.Group)
                        {
                            if (item.Disabled)
                            {
                                <option value="@item.Value" disabled = "disabled">@item.Text</option>
                            }
                            else
                            {
                                <option value="@item.Value">@item.Text</option>
                            }
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td>Distribution:</td>
                <td>
                    <select id="Distribution" name="Distribution" onchange="javascript:UpdateTime();">
                        @foreach (var item in (List<SelectListItem>)ViewBag.Distribution)
                        {
                            if (item.Selected)
                            {
                                <option value="@item.Value" selected = "selected">@item.Text</option>
                            }
                            else
                            {
                                <option value="@item.Value">@item.Text</option>
                            }
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td>Enable Self Learning Mode:</td>
                <td><input type="checkbox" name="enableSLM" id="enableSLM" value="true" checked onchange="javascript:UpdateTime();" /></td>
            </tr>
        </table>
    </div>
    <div id="executeProfiles">
        @if (((string)ViewBag.Error).Length > 0)
        {
            <div style="color: red; font-size: large;">@ViewBag.Error</div>
        }
        <table>
            <tr>
                <th colspan="2" style="text-align: center">Available runtimes</th>
            </tr>
            <tr>
                <td colspan="2" style="text-align: right; padding-right: 2em;"><a href="#" onclick="javascript:$('[id^=chk_]').prop('checked', true);UpdateTime();">Select All</a>&nbsp;&nbsp;<a href="#" onclick="javascript:$('[id^=chk_]').prop('checked', false);UpdateTime();">Select None</a></td>
            </tr>
            @foreach (var profile in Model)
            {
                var profileType = profile.IsSprint ? "Sprint" : profile.IsSXP ? "SXP" : "DX";
                <tr>
                    <td>@Html.TextBoxFor(item => profile.ProfileName, new { @class = "profileName", profileType, @id = profile.ProfileID })</td>
                    <td>@Html.CheckBox("chk_" + profile.ProfileID, new { onchange = "javascript:ShowVersionPopup(this, false);UpdateTime(this);", profileType })</td>
                </tr>
            }
        </table>
    </div>
    <br />
    @Html.Hidden("DXVersion")
    <p>&nbsp;</p>
    <div style="font-weight: bold">
        Estimated run time: <span id="runtime" style="color: purple">N/A</span>
    </div>
    <p id="executeSubmit">
        <input type="submit" name="Execute" value="Run Now" />
        <input type="button" id="schedule-button" value="Schedule as Task" />
    </p>
    @{
        Html.EndForm();
    }
</div>

@(Html.Kendo().Window()
    .Name("scheduler-dialog")
    .Title("Task scheduler")
    .Actions(actions => actions
        .Close()
    )
    .Content(@<text>
                  <form action="#" name="sFrm" id="sFrm" method="POST">
                  <table style="width: 100%; text-align: left;">
                      <tbody>
                          <tr>
                              <td>
                                  Start Date:                               
                                  @(Html.Kendo().DatePicker()
                                     .Name("startDate")
                                     .Value(DateTime.Today)
                                     .HtmlAttributes(new { style = "width: 150px" }))

                              </td>
                              <td>
                                  Start Time:
                                  @(Html.Kendo().TimePicker()
                                     .Name("startTime")
                                     .Value(DateTime.Now)
                                     .HtmlAttributes(new { style = "width: 150px" }))
                              </td>
                          </tr>
                          <tr>
                              <td colspan="2">@Html.CheckBox("isRecurring") Recurring task</td>
                          </tr>
                          <tr>
                              <td colspan="2">
                                  <input style="clear: both; width: auto;" name="recPat" type="radio" value="1" checked="checked" />Daily
                                  <input style="clear: both; width: auto;" name="recPat" type="radio" value="2" />Weekly
                                  <input style="clear: both; width: auto;" name="recPat" type="radio" value="4" />Monthly
                              </td>
                          </tr>
                          <tr>
                              <td colspan="2">
                                  End Date (optional):
                                  @(Html.Kendo().DatePicker()
                                  .Name("endDate")
                                  .HtmlAttributes(new { style = "width: 150px" }))
                              </td>
                          </tr>
                      </tbody>
                  </table>

                  <input type="button" id="scheduler-close" value="OK" />
                  </form>
    </text>)
    .Width(750)
    .Modal(true)
    .Visible(false)
)

<script>
    $(document).ready(function () {
        var dialog = $("#scheduler-dialog").data("kendoWindow");
        dialog.center();

        $("#schedule-button").bind("click", function () {
            dialog.open();
        });

        $("#scheduler-close").bind("click", function () {
            dialog.close();
            var action = $('#eFrm').attr('action');
            $.ajax({
                url: action,
                type: 'POST',
                data: $('#eFrm, #sFrm').serialize(),
                success: function () {
                    alert('Task scheduled');
                }
            });
        });
    });
</script>

<div id="overlay" class="web_dialog_overlay"></div>
   
<div id="dialog" class="web_dialog">
   <table style="width: 100%; border: 0px;" cellpadding="3" cellspacing="0">
      <tr>
         <td class="web_dialog_title">Please enter version</td>
         <td class="web_dialog_title align_right">
            <a href="#" id="btnClose">Cancel</a>
         </td>
      </tr>
      <tr>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" style="padding-left: 15px;">
            <b>Please choose version: </b>
         </td>
      </tr>
      <tr>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" style="padding-left: 15px;">
             <div id="version">
                 @Html.TextBox("ver")
             </div>
         </td>
      </tr>
      <tr>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" style="text-align: center;">
            <input id="btnSubmit" type="button" value="Submit" />
         </td>
      </tr>
   </table>
</div>